#!/bin/bash
. /etc/profile

cd `dirname $0`
BIN_DIR=`pwd`
FILE_NAME=`basename $0`
echo "$FILE_NAME"
cd ..
DEPLOY_DIR=`pwd`
#echo $DEPLOY_DIR
ps aux| grep java |grep "$DEPLOY_DIR/" | grep -v grep| grep -v "$FILE_NAME" |awk '{print $2}'|xargs -i echo {}
ps aux| grep java |grep "$DEPLOY_DIR/" | grep -v grep| grep -v "$FILE_NAME" |awk '{print $2}'|xargs -i kill {}

COUNT=1
while [ $COUNT -gt 0 ]; do
    echo -e ".\c"
    sleep 1
#   if [ -n "$SERVER_PORT" ]; then
#       COUNT=`echo status | nc 127.0.0.1 $SERVER_PORT -i 1 | grep -c OK`
#   else
        COUNT=`ps  --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR/" | awk '{print $2}' | wc -l`
#  fi
        if [ $COUNT -lt 1 ]; then
                break
        fi
done
echo "Stop OK!"
